<template>
  <div>
    <van-nav-bar title="绑定支付宝" left-arrow @click-left="leftClick" />
    <van-tabs
      v-model="active"
      color="#1777ff"
      title-active-color="#1777ff"
      itle-inactive-color="#444"
    >
      <van-tab title="手机号">
        <van-field
          class="phone"
          v-model="phone"
          type="tel"
          label="手机号"
          placeholder="请输入手机号"
        />
        <van-field
          v-model="sms"
          center
          clearable
          label="验证码"
          placeholder="请输入验证码"
        >
          <template #button>
            <div class="sms-div" @click="smsClick">{{ smsText }}</div>
          </template>
        </van-field>
        <p class="phone-p">为确保是您本人操作的支付宝授权，须进行短信校验</p>
        <div class="phone-next" @click="phoneClick">确定绑定</div>
      </van-tab>
      <van-tab title="邮箱">
        <van-field
          class="phone"
          v-model="mailbox"
          type="text"
          label="邮箱"
          placeholder="请输入邮箱"
        />
        <p class="phone-p">为确保提现到账，邮箱须为您开通的支付宝账户</p>
        <div class="phone-next">确定绑定</div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import { getApiSms, getApiSMSVerification } from "network/ApiServe";
export default {
  name: "Alipay",

  data() {
    return {
      active: 0,
      phone: "",
      sms: "",
      mailbox: "",
      smsText: "发送验证码",
    };
  },
  methods: {
    leftClick() {
      this.$router.back(-1);
    },
    smsClick() {
      let _this = this;
      if (_this.phone.length != 11) {
        return _this.$toast("请输入手机号或者手机号格式不正确");
      }
      let timeSS = 4;
      let clearTime = setInterval(() => {
        timeSS--;
        if (timeSS == 0) {
          clearInterval(clearTime);
          _this.smsText = "发送验证码";
          return;
        }
        _this.smsText = timeSS + "s";
      }, 1000);
      getApiSms(_this.phone)
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    phoneClick() {
      let _this = this;
      if (_this.phone.length != 11) {
        return _this.$toast("请输入手机号或者手机号格式不正确");
      }
      if (_this.sms.length == 0) {
        return _this.$toast("请输入验证码");
      }
      getApiSMSVerification(this.phone, this.sms)
        .then((res) => {
          console.log(res, "getApiSMSVerification");
          if (res.resp_code === "000000") {
            _this.phone = "";
            _this.sms = "";
          }
          this.$toast(res.resp_message);
        })
        .catch((err) => {
          console.log(err, "getApiSMSVerification");
        });
    },
  },
};
</script>
<style scoped>
.van-nav-bar >>> .van-icon {
  color: #444;
}
.phone {
  margin-top: 15px;
  margin-bottom: 1px;
}
.van-tab__pane >>> .van-field__label {
  width: 46px;
}
.phone-p {
  margin-top: 15px;
  margin-left: 15px;
  font-size: 12px;
  color: #999;
}
.phone-next {
  margin-top: 40px;
  margin-left: 52px;
  margin-right: 52px;
  background-color: var(--app-primary-theme-color);
  border-radius: 4px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 15px;
}
.sms-div {
  color: var(--app-primary-theme-color);
}
</style>